#include "bsp_handle.h"

void d_input_init(void)
{
    CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
    CKCUClock.Bit.PA        = 1;
    CKCUClock.Bit.PB        = 1;
    CKCUClock.Bit.AFIO      = 1;
    CKCU_PeripClockConfig(CKCUClock, ENABLE);
    p_io_init(MOTOR_AFIO,MOTOR_GPIO,MOTOR_PIN,GPIO_DIR_OUT,GPIO_PR_DISABLE);
    GPIO_InputConfig(MOTOR_GPIO,MOTOR_PIN, ENABLE);

    p_io_init(OUTR_AFIO,OUTR_GPIO,OUTR_PIN,GPIO_DIR_OUT,GPIO_PR_DISABLE);
    OUTR_OFF;

    p_io_init(OUT_AFIO,OUT_GPIO,OUT_PIN,GPIO_DIR_OUT,GPIO_PR_DISABLE);
    OUT_OFF;

    p_io_init(SMK_AFIO,SMK_GPIO,SMK_PIN,GPIO_DIR_IN,GPIO_PR_UP);
    p_io_init(CLRK_AFIO,CLRK_GPIO,CLRK_PIN,GPIO_DIR_IN,GPIO_PR_UP);
}

void d_input_deinit(void)
{

}

void d_output_init(void)
{

}

void d_output_deinit(void)
{

}


void d_key_scan(void)
{
    static u16 smk_press_count=0;
    static u16 clek_press_count=0;
    static u16 mi_press_count = 0;
    static u8  mi_press_flg = 0;
    static u16 mi_up_count = 0;
    static u16 smk_act_click=0;
    static u16 clek_act_click=0;
    static u16 release_count=0;
    static u16 key_status = 0;

 //   key_status = (GPIO_ReadInBit(SMK_GPIO,SMK_PIN)<<1)+ \
 //                   GPIO_ReadInBit(CLRK_GPIO,CLRK_PIN);
   key_status =  (u16)HT_GPIOA->DINR;

   if (key_status == SMK_PRESS)
   {
        release_count = 0;
        clek_press_count = 0;
        smk_press_count++;
        clek_act_click = 0;
   }
   else if (key_status == CLK_PRESS)
   {
        clek_press_count++;
        release_count = 0;
        smk_press_count = 0;
        smk_act_click = 0;
   }
   else if (key_status == ALL_KEY_RELEASE)
   {
        release_count++;
        clek_press_count = 0;
        smk_press_count = 0;
 //       gexti_click = 0;
   }
   else
   {
        release_count++;
        clek_press_count = 0;
        smk_press_count = 0;
//        gexti_click = 0;
   }
}


